package com.kehutong.payfees.util;

import org.coraframework.json.JSONObject;
import org.coraframework.orm.jdbc.execute.QueryCondition;
import org.coraframework.orm.jdbc.execute.entity.FindArray;
import org.coraframework.orm.jdbc.execute.entity.FindPage;
import org.coraframework.util.Objects;

public class JDBCUtil {

    public static void between(JSONObject jsonObject, QueryCondition find, String name) {
        String beginTime = jsonObject.getString("beginTime");
        if (Objects.nonEmpty(beginTime) && beginTime.length() == 10) {
            beginTime += " 00:00:00";
        }

        String endTime = jsonObject.getString("endTime");
        if (Objects.nonEmpty(endTime) && endTime.length() == 10) {
            endTime += " 23:59:59";
        }

        if (Objects.nonEmpty(beginTime) && Objects.nonEmpty(endTime)) {
            find.between(name, beginTime, endTime);
        } else if (Objects.nonEmpty(beginTime)) {
            find.max(name, beginTime);
        } else if (Objects.nonEmpty(endTime)) {
            find.min(name, endTime);
        }
    }

    public static void between(JSONObject jsonObject, FindArray find, String name) {
        String beginTime = jsonObject.getString("beginTime");
        if (Objects.nonEmpty(beginTime) && beginTime.length() == 10) {
            beginTime += " 00:00:00";
        }

        String endTime = jsonObject.getString("endTime");
        if (Objects.nonEmpty(endTime) && endTime.length() == 10) {
            endTime += " 23:59:59";
        }

        if (Objects.nonEmpty(beginTime) && Objects.nonEmpty(endTime)) {
            find.between(name, beginTime, endTime);
        } else if (Objects.nonEmpty(beginTime)) {
            find.max(name, beginTime);
        } else if (Objects.nonEmpty(endTime)) {
            find.min(name, endTime);
        }
    }

    public static void between(JSONObject jsonObject, FindPage find, String name) {
        String beginTime = jsonObject.getString("beginTime");
        if (Objects.nonEmpty(beginTime) && beginTime.length() == 10) {
            beginTime += " 00:00:00";
        }

        String endTime = jsonObject.getString("endTime");
        if (Objects.nonEmpty(endTime) && endTime.length() == 10) {
            endTime += " 23:59:59";
        }

        if (Objects.nonEmpty(beginTime) && Objects.nonEmpty(endTime)) {
            find.between(name, beginTime, endTime);
        } else if (Objects.nonEmpty(beginTime)) {
            find.max(name, beginTime);
        } else if (Objects.nonEmpty(endTime)) {
            find.min(name, endTime);
        }
    }
}
